#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui>

class RightWidget;
class TargetManager;

class DialogSaveAs : public QDialog
{
    Q_OBJECT
public:
    DialogSaveAs(const QString& name,const QString& path,QWidget* parent=0);
    virtual ~DialogSaveAs();

public:
    QString getName(){return m_name;}
    QString getPath(){return m_path;}

protected slots:
    virtual void accept();
    void browseClicked();

private:
    QLineEdit* m_leName;
    QLineEdit* m_lePath;

    QPushButton* m_pbBrowse;
    QPushButton* m_pbOk;
    QPushButton* m_pbCancel;

    QString m_name;
    QString m_path;
};

class DialogTargetConfig : public QDialog
{
    Q_OBJECT
public:
    DialogTargetConfig(const QString& ip,quint16 port);
    virtual ~DialogTargetConfig();

public:
    QString getIp(){return m_ip;}
    quint16 getPort(){return m_port;}

protected slots:
    virtual void accept();

private:
    QLineEdit* m_leIp;
    QLineEdit* m_lePort;

    QPushButton* m_pbOk;
    QPushButton* m_pbCancel;

    QString m_ip;
    quint16 m_port;
};

class DialogTargetChangeSector : public QDialog
{
    Q_OBJECT
public:
    DialogTargetChangeSector(const QStringList& lstSector,const QString& activeSector,
        QWidget* parent=0);
    ~DialogTargetChangeSector();

public:
    QString& activeSector(){return m_activeSector;}

protected slots:
    virtual void accept();

    void newSector(bool checked);
    void existSector(bool checked);

private:
    QRadioButton* m_rbNewSector;
    QRadioButton* m_rbExistSector;
    QLineEdit* m_leSector;
    QComboBox* m_cbSector;

    QPushButton* m_pbOk;
    QPushButton* m_pbCancel;

    QString m_activeSector;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

protected slots:
    void newProject();
    void openProject();
    void save();
    void saveAs();
    void connectDevice();
    void disConnectDevice();
    void readParm();
    void writeParm();
    void targetConfig();
    void tgtSectorChange();

    void debugStart();
    void debugStop();

    void targetConnectStatus(bool status);

    void optionChanged(QListWidgetItem*);

    void configModified();

    void targetModified();

private:
    void resetRightView();
    void resetTitle();

    bool loadParm();
    bool saveParm(const QString& path);

    void makeDefaultParm();

public:
    static bool removeDir(const QString& dirName);

private:
    QMenuBar* m_pMainMenu;
    QAction* m_actNewPjt;
    QAction* m_actOpenPjt;
    QAction* m_actSave;
    QAction* m_actSaveAs;

    QAction* m_actConnect;
    QAction* m_actDisConnect;
    QAction* m_actTarget;
    QAction* m_actTgtSector;
    QAction* m_actReadParm;
    QAction* m_actWriteParm;

    QAction* m_actDebugStart;
    QAction* m_actDebugStop;

    QStatusBar* m_statusBar;
    QLabel* m_msgConnect;

    QListWidget* m_widgetOption;

    QFrame* m_rightHolder;

    RightWidget* m_hardwareView;
    RightWidget* m_deviceView;
    RightWidget* m_deviceProtocolView;
    RightWidget* m_protocol103View;

    RightWidget* m_targetView;

    QString m_title;

    QString m_curProjectName;
    QString m_curProjectPath;

    QString m_curOption;

    TargetManager* m_target;
    bool m_targetStatus;
    QString m_targetIp;
    quint16 m_targetPort;

    bool m_bProjectExits;
    bool m_bProjectNew;
    bool m_bconfigChanged;
};

#endif // MAINWINDOW_H
